package 可重入锁.用阻塞队列的生产者消费者;

import java.util.concurrent.BlockingQueue;

public class Produce implements Runnable {

    BlockingQueue<Integer> queue ;

    public Produce(BlockingQueue<Integer> queue) {
        this.queue = queue;
    }

    @Override
    public void run() {
        while (true) {
            try {
//                queue.put(1);
                int a = (int) (Math.random() * 100);
                if (!queue.offer(a)) {
                    System.out.println(Thread.currentThread().getName() + " 等待");
                }
                System.out.println(Thread.currentThread().getName() + " 放入 " + a);
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    }
}
